package api

import (
	rich_err "app/error"
	"app/utils"
	"fmt"
	"github.com/GoAdminGroup/go-admin/engine"
	"github.com/gin-gonic/gin"
)

func BasicAuth() gin.HandlerFunc {
	return func(context *gin.Context) {
		user, _ := engine.User(context)
		if user.Id == 0 {
			utils.GinJSONWithRichErr(context, nil, rich_err.NewError(rich_err.Forbidden, fmt.Errorf("用户未登录")))
			context.Abort()
			return
		}
		// TODO
		// 判断登录,以及登录用户的role,是否有权限使用当前的api
		context.Next()
	}
}
